/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.casemain.controller;

import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.AfterPunishRevokeDealDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CasePunishDecisionRevokeRecordDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICasePunishDecisionRevokeRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CasePunishDecisionRevokeRecordVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 描述：描述：案件处罚决定撤销记录前端控制器
 *
 * @author xiangyuyu
 * @date 2022/7/22
 * @since 1.3.2
 */
@RestController
@RefreshScope
@RequestMapping("/punish/ucase/case/main/punish/decision/revoke")
@Slf4j
public class CasePunishDecisionRevokeRecordController extends BaseController {
    @Resource
    private ICasePunishDecisionRevokeRecordService casePunishDecisionRevokeRecordService;


    /**
     * 【V1.3.2】描述：保存案件处罚决定撤销记录基本信息
     *
     * @param saveDto {@link CasePunishDecisionRevokeRecordDto}
     * @return {@link Result <String>} 保存结果
     * @author xiangyuyu
     * @date 2022/7/21
     * @since 1.3.2
     */
    @PostMapping("/saveCasePunishDecisionRevokeRecordBasicInfo")
    @ApiOperation(value = "【V1.3.2】描述：保存案件处罚决定撤销记录基本信息息", httpMethod = "POST")
    public Result<String> saveCasePunishDecisionRevokeRecordBasicInfo(@RequestBody @Validated CasePunishDecisionRevokeRecordDto saveDto) {
        int count = casePunishDecisionRevokeRecordService.saveCasePunishDecisionRevokeRecordBasicInfo(saveDto);
        return (count == Constant.INTEGER_1) ?
                Result.success(Constant.STRING_SAVE_SUCCESS) : Result.error(Constant.STRING_SAVE_FAIL);

    }


    /**
     * 【V1.3.2】描述：根据案件id查询案件处罚决定撤销记录基本信息
     *
     * @param caseId 案件id
     * @return {@link Result<CasePunishDecisionRevokeRecordVo>}
     * @author xiangyuyu
     * @date 2022/7/21
     * @since 1.3.2
     */
    @PostMapping("/getCasePunishDecisionRevokeRecordBasicInfo")
    @ApiOperation(value = "【V1.3.2】描述：根据案件id查询案件处罚决定撤销记录基本信息", httpMethod = "POST")
    public Result<CasePunishDecisionRevokeRecordVo> getCasePunishDecisionRevokeRecordBasicInfo(@RequestParam String caseId) {
        CasePunishDecisionRevokeRecordVo vo = casePunishDecisionRevokeRecordService.getCasePunishDecisionRevokeRecordBasicInfo(caseId);
        return Result.success(Constant.STRING_GET_SUCCESS, vo);
    }

    /**
     * 描述：处罚决定撤销后续处理
     *
     * @param dto {@link AfterPunishRevokeDealDto}
     * @return Result<String> 处理结果
     * @author xiangyuyu
     * @date 2022/7/28
     * @since 1.3.2
     */
    @PostMapping("/dealAfterPunishRevoke")
    @ApiOperation(value = "【V1.3.2】描述：根据案件id查询案件处罚决定撤销记录基本信息", httpMethod = "POST")
    public Result<String> dealAfterPunishRevoke(@RequestBody @Validated AfterPunishRevokeDealDto dto) {
        String errorMsg = casePunishDecisionRevokeRecordService.dealAfterPunishRevoke(dto.getCaseId(), dto.getDealAfterRevokeTypeCode());
        if (ObjectUtils.isEmpty(errorMsg)) {
            return Result.success("处理成功");
        } else {
            return Result.error(errorMsg);
        }
    }
}